how to check if record exists before insert in c